<template>
	<view class="bods" style="margin-top: 150rpx;">
			<view class="bodtitle">
				<p><b>费用预算</b></p>
			</view>
			<u-form labelPosition="left" v-for="(item,index) in busiTripdEntityList" :key="index" style="margin: 10px 10px 0 10px; background: #fff;":id="'busiTripdEntityList'+item.empNm" :style = "{border:textClass == ('busiTripdEntityList'+item.empNm)?'1px solid #539ce7b3':''}">
				<!-- 申请人 -->
				<u-form-item required labelWidth="170rpx" label="申请人" prop="userInfo.name" borderBottom ref="item1" >
					<input class="pdlf" type="text" disabled v-model="item.empNm">
					<!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
				</u-form-item>

				<!-- 申请金额 -->
				<u-form-item required labelWidth="200rpx" label="申请金额" borderBottom ref="item2">
					<input class="pdlf" type="number" v-model="item.totAmt" placeholder="请填写申请金额">
				</u-form-item>
				<view class="skyb">
					<label class="lab">{{item.budgetNo}}</label>
					<view class="skyblu">
						<span>费用科室</span>
						<p style="display: flex;flex:2;justify-content: flex-end;" @click="selectDepartment(item,index)">{{item.subdeptNm}}<u-icon slot="right" name="arrow-right"></u-icon></p>
					</view>
					<view class="skyblu">
						<span>预算号名称</span>
						<p @click = "budgetClick(index)" style="display: flex;flex:2;justify-content: flex-end;">{{item.budgetNm}}<u-icon slot="right" name="arrow-right"></u-icon></p>
					</view>
				</view>
			</u-form>
		</view>
<!-- 		<view class="addbtn">
			<view style='width: 90%;margin: 0 auto;margin-bottom: 30rpx;' @click="addbudget()">
				<view class="update">
					<p>
						<image src="@/static/newimg/tJ.svg" mode=""></image>
						<span style='color: #007aff;padding-left: 10rpx;'>添加同行人费用</span>
					</p>
				</view>
			</view>
		</view> -->
		<!-- <view class="bottom_setup">
			<view class="bottom_white">
				<u-button @click="headback"  class="custom-styles" :plain="true" type="primary" :text="backtitle"></u-button>
				<u-button @click="ngtocost()" class="custom-style" type="primary" :text="nexttitle"></u-button>
			</view>
		</view> -->
		
	</view>
</template>

<script>
	import Setps from '@/workspaces/tools/setps.vue'
	import Nextbtn from '@/workspaces/tools/nextbtn.vue'
	export default {
		props:['list'],
		data() {
			return {
				textClass:'',
				busiTripdEntityList:[],//预算信息
				headtitle: '出差申请',
				name: 2,
				backtitle:'上一步(行程计划)',
				nexttitle:'下一步(信息确认)',
				next:'./submission',
				appId: "",
				wiid: "",
				formAction: "",
				taskId: "",
				wfContext: {},
				isReadOnly: false
			}
		},
		mounted(){
			let _this = this;
			window.myvm = _this;
			window.$urlFormVue = _this;
			let peersNum =this.list.peersNum? Number(this.list.peersNum):0;
			 this.busiTripdEntityList=this.list.busiTripdEntityList;
			 this.getExpenseDepartment(this.list.subdeptId)
			 
			 //获取流程页面的流程上下文[实用的流程信息从这里获取]
			 _this.wfContext = window.parent.myvm.wfContext;
			 console.info(_this.wfContext);
			 //流程应用定义ID
			 var appId = Object.toQueryString("appId") || "";
			 //流程实例ID
			 var wiid = Object.toQueryString("wiid") || "";
			 if (wiid == "") {
			   wiid = _this.wfContext.WorkflowInstanceId;
			 }
			 //  当前页面状态：0未有实例，2待办，3查看,4待阅
			 var formAction = Object.toQueryString("formAction") || 0;
			 //待办任务ID，待办时才有此参数
			 var taskId = Object.toQueryString("taskId") || "";
			 if (formAction > 2) {
			   _this.isReadOnly = true;
			 }
			 _this.appId = appId;
			 _this.wiid = wiid;
			 _this.formAction = formAction;
			 _this.taskId = taskId;
		},
		methods: {
			nextStep(btnDef, callback){
				if(this.ngtocost()){
					return callback(4);
				}
				callback("");
			},
			upStep(btnDef, callback){
				if(this.headback()){
					return callback(2);
				} else {
					callback("");
				}
			},
			validateWorkflowForm(btnDef, callback) {
				if(btnDef.buttonName != "暂存"){
					if(this.wfContext.WorkflowInstinceState == 0 || this.wfContext.WorkflowInstinceState == 1 || this.wfContext.WorkflowInstinceState == 5){
						return callback("请点击下一步填写确认申请信息");
					}
				}
				callback("");
			},
			//暂存-工作流点击"保存"时触发此函数，返回true:工作流继续提交， false:工作流不提交
			saveWorkflow(btnDef, callback) {
				let _this= this;
				if(_this.travelTrip == "1"){//变更保存
					this.list.billStatus= "0";
					_this.$lyRequest.post("/gateway/reim/mp/dbsap/busiTripmEntity/changeBusiTrip.do", _this.list).then(result=>{
					  if(result.data && result.data.result == 1){
					    callback("", result.data.rows.billNo);
					  }else{
						callback(result.data.msg);
					  }
					});
				} else {
					this.list.billStatus= "0";
					_this.$lyRequest.post("/gateway/reim/mp/dbsap/busiTripmEntity/saveBusiTripm.do", _this.list).then(result=>{
					  if(result.data && result.data.result == 1){
					    callback("", result.data.rows.billNo);
					  }else{
						callback(result.data.msg);
					  }
					});
				}
			},
			//预算校验
			verificationData() {
				let _this = this;
				_this.verIndex = "";
				let verShow = false;
				let busiTripdEntityList = _this.busiTripdEntityList;
				for (let i = 0; i < busiTripdEntityList.length; i++) {
					_this.verIndex = i;
					if (busiTripdEntityList[i].totAmt == '') {
						_this.assignment("busiTripdEntityList", busiTripdEntityList[i].empNm, "申请金额");
						verShow = true;
						break;
					} else if (busiTripdEntityList[i].budgetNm == '') {
						_this.assignment("busiTripdEntityList", busiTripdEntityList[i].empNm, "预算");
						verShow = true;
						break;
					} 
				}
				return verShow;
			},
			assignment(name, i, text) {
				this.textClass = name + i;
				this.commonApi.goAnchor(name + i);
				this.$api.showTip(`${i}${text}不能为空`);
			},
			//选择预算
			budgetClick(index){
				uni.navigateTo({
					url:'../../components/components/budget?trip='+index
				})
			},
			// 选择费用承担科室
			selectDepartment(item,index){
				uni.navigateTo({
					url:'../../components/components/expenseDepartment?trip='+index
				})
			},
			//选择出差申请人
			personClick(carryJudag,index){
				uni.navigateTo({
					url:'../../components/components/personnelList?carryJudag='+carryJudag+'&tripIndex='+index
				})
			},
			addbudget(){
				this.busiTripdEntityList.push({
					budgetMId:'',//	预算信息主表ID	String	T
					budgetNo:'',//	预算号	String	T
					budgetNm:'',//	预算名称	String	T
					empNm:'',//	申请人	String	T
					empNo:'',//	申请人工号	String	T
					subdeptId:'',//	科室编码	String	T
					subdeptNm:'',//	科室名称	String	T
					totAmt:'',//	申请金额	Double	T	
				})
			},
			//请求费用科室
			getExpenseDepartment(subdeptId){
				let _this = this;
				_this.$lyRequest.get('/gateway/budget/mp/dbsap/basedata/budget/queryList.do', {
					budgetType: '1',
					subdeptId: subdeptId,
					budgetYear: _this.$oacommon.getNewDate(true, 'Y').retTwo,
				 }).then(data => {
					if (data.data.result == "1") {
						if (data.data.rows) { 
							_this.busiTripdEntityList[0].budgetNo = data.data.rows[0].budgetNo;
							_this.busiTripdEntityList[0].budgetNm = data.data.rows[0].budgetNm;
						}
					}
				});
			},
			// 上一步
			headback(){
				let _this = this;
				_this.$emit('modifyNum',1,_this.list)
				return true
			},
			// 下一步
			ngtocost(){
				let _this = this;
				if (_this.verificationData() == true) return false;
				_this.$emit('modifyNum',3,_this.list)
				return true
			},
		},
		components: {
			Setps,
			Nextbtn
		}
	}
</script>

<style scoped lang="scss">
	view{
		font-family: pf;
	}
	.pdlf {
			padding-left: 60rpx;
	}

	.skyb {
		width: 100%;
		background: #ffffff;

		.lab {
			display: block;
			height: 80rpx;
			line-height: 80rpx;
			padding-left: 10rpx;
			border-bottom: 1px solid #f1f1f1;
			font-weight: bold;
		}
		.skyblu{
			display: flex;
			flex-direction: row;
			padding: 20rpx 20rpx;
			span{
				width: 200rpx;
			}
			p{
				margin-left: 30rpx;
			}
		}
	}

	.addbtn {
		width: 90%;
		background-color: white;
		margin: 0 auto;
		height: 100rpx;
		padding: 10rpx 0;
		box-sizing: border-box;
        margin-bottom: 80rpx;
		.btn {
			width: 90%;
			margin: 0 auto;
		}
	}
	.update {
			width: 100%;
			height: 80rpx;
			border: 1px solid #007aff;
			border-radius: 4px;
			display: flex;
			align-items: center;
			justify-content: center;
			p {			
				image {
					width: 40rpx;
					height: 40rpx;
					vertical-align: bottom;
				}
			}
		}
	.bottom_setup {
		position: fixed;
		bottom: 30rpx;
		right: 0;
		width: 100%;
		height: 160rpx;
		background-color: white;
		margin-top: 40rpx;
		padding: 35rpx 0;
		box-sizing: border-box;
	}
	.bottom_setup{
			width: 100%;
			background-color: white;
			box-shadow: 5px -10rpx 5px 0px rgba(225, 225, 225,.4),;
			position: fixed;
			bottom: 0;
			.bottom_white{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-between;
				// height: 150rpx;
				.custom-styles{
					padding: 20rpx 30rpx;
					width: 300rpx;
					height: 100rpx;
				}
				.custom-style{
					padding: 20rpx 30rpx;
					width: 300rpx;
					height: 100rpx;
					background-color: #007aff;
				}
			}
		}
</style>
